<?php

/**
 * Employee form.
 *
 * @package    Amawal Invest
 * @subpackage form
 * @author     Ameen Shoman<amin.shoman@gmail.com>
 */
class EmployeeForm extends BaseEmployeeForm
{
    public function configure()
    {
        if(!sfContext::getInstance()->getUser()->hasCredential('super_admin')){
            unset($this['branch_id']);
        }
        unset($this['link_employee_leave_list']);

        $this->validatorSchema['department_id']->setOption( 'required' , true );
        $this->validatorSchema['section_id']->setOption( 'required' , true );

        $this->validatorSchema['hiring_date']->setOption( 'required' , true );
        $this->validatorSchema['birth_date']->setOption( 'required' , true );

        $years = range(date('Y') - 75, date('Y') - 15);
        $years2 = range(date('Y') - 50, date('Y') );

		### oringial dates
        $this->widgetSchema['birth_date'] = new sfWidgetFormDate(array('years'=>array_combine($years,$years)));
        $this->widgetSchema['hiring_date'] = new sfWidgetFormDate(array('years'=>array_combine($years2,$years2)));
        ### jquery dates
        
              

        $this->widgetSchema['birth_date'] = new sfWidgetFormJQueryDate(array('date_widget'=>$this->widgetSchema['birth_date'],'config'=>'{changeMonth: true,changeYear: true,yearRange: "'.min($years).':'.max($years).'"}'));
        $this->widgetSchema['hiring_date'] = new sfWidgetFormJQueryDate(array('date_widget'=>$this->widgetSchema['hiring_date'],'config'=>'{changeMonth: true,changeYear: true,yearRange: "'.min($years2).':'.max($years2).'"}'));
        
        $this->validatorSchema['card_id'] = new sfValidatorInteger();
        
        
        $this->widgetSchema['section_id'] = new sfWidgetPropelAjaxBind(array('model'=>'CodeSection','change_widget'=>'department_id'));
        
        //$this->getValidatorSchema()->setPostValidator( sfValidatorPropelUnique() );
        
        
        if(!$this->isNew()){
        	$this->widgetSchema['card_id']->setAttribute('readonly','readonly');
        	$this->getWidgetSchema()->setHelp('card_id','This field is readonly');
        	$this->widgetSchema['code']->setAttribute('readonly','readonly');
        	$this->getWidgetSchema()->setHelp('code','This field is readonly');
        }
        

    }
}


